﻿using EMoney.IStock.Client.DataAccess.MC;
using EMoney.IStock.Client.Framework;
using EMoney.IStock.Client.Models.MC;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EMoney.IStock.Client.Business.MC
{
    /// <summary>
    /// 任务完成条件类型业务处理类
    /// </summary>
    public class TaskConditionTypeBll
    {
        private object objTaskConditionType = new object();

        private const string TASKCONDITIONTYPE_MEMCACHED_KEY = "EMoney.IStock.Client.Business.MC.TaskConditionTypeBll.TaskConditionType";

        /// <summary>
        /// 获取任务完成条件
        /// </summary>
        /// <returns></returns>
        public List<MC_TaskConditionType> GetTaskConditionList()
        {
            List<MC_TaskConditionType> list = CacheManager.RedisCache.Get<List<MC_TaskConditionType>>(TASKCONDITIONTYPE_MEMCACHED_KEY);

            if (list == null)
            {
                try
                {
                    lock (objTaskConditionType)
                    {
                        list = CacheManager.RedisCache.Get<List<MC_TaskConditionType>>(TASKCONDITIONTYPE_MEMCACHED_KEY);

                        if (list == null)
                        {
                            TaskConditionTypeDal taskConditionTypeDal = new TaskConditionTypeDal();

                            list = taskConditionTypeDal.GetTaskConditionTypeList();

                            if (list == null)
                            {
                                list = new List<MC_TaskConditionType>();
                            }

                            CacheManager.RedisCache.Set<List<MC_TaskConditionType>>(TASKCONDITIONTYPE_MEMCACHED_KEY, list);
                        }
                    }
                }
                catch (Exception ex)
                {
                    LogManager.DefaultLogger.Error(ex, "获取任务完成条件类型失败");
                }
            }

            return list;
        }
    }
}
